package com.example.demo.user.controller;

import com.example.demo.entity.SysUserDto;
import com.example.demo.util.MachUtil;
import org.apache.shiro.crypto.hash.Sha256Hash;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Classname UserLogin
 * @Description TODO
 * @Date 2019/12/10 9:47
 * @Created by yby
 */
@RestController
@RequestMapping("user")
public class UserLogin {
    //盐值加密流程：存入时对salt和输入的password字段进行加密存入password字段里，登录取出时根据输入的pwd

    @RequestMapping("/add")
    public void addUser(SysUserDto sysUserDto){
        sysUserDto.setSalt(MachUtil.createRandomStringData(6));//产生六位随机数
        sysUserDto.setPassword(new Sha256Hash(sysUserDto.getPassword(), sysUserDto.getSalt()).toHex());//盐值加密
    }

    @RequestMapping("/login")
    public void loginUser(String userName, String password){
        //根据用户名去查数据库
        //用户信息
        //SysUserEntity user = sysUserService.queryByUserName(username);
        //判断密码
        //if(user.getPassword().equals(new Sha256Hash(password, user.getSalt()).toHex()));
    }

}
